-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Conversation
The _value field wasn't previously readonly, because method calls were made on the ValueTask, resulting in a copy. But now that ValueTask is a readonly struct, the field can be readonly, and these structs can then also be readonly.
It was superfluous and made sharing the code with corefx more challenging due to the netstandard1.0 build of System.Threading.Tasks.Extensions in corefx.
@dotnet-bot test this please (most legs didn't start) |
@dotnet/dnceng, is there an issue with legs getting started in coreclr? |
@stephentoub I think so...investigating. |
@dotnet-bot test this please |
|
||
private bool IsTaskCompletedSuccessfully => _task.IsCompletedSuccessfully; | ||
|
||
private Task<TResult> GetTaskForResult() => AsyncTaskMethodBuilder<TResult>.GetTaskForResult(_result); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these extra layers going to regress perf? Note that the JIT is not great at inlining a complex generic constructs like these.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it ends up being a problem, I expect the best recourse would be to just ifdef it. Is there a compilation constant we use for this kind of thing? #if CORECLR
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should be using #if netstandard
for the less efficient portable version since the portable version is the odd one. Everything else will want to use the more efficient version - CORECLR, CORERT, MONO.
{ | ||
readonly partial struct ValueTask<TResult> | ||
{ | ||
private static void ThrowNullTaskException() => ThrowHelper.ThrowArgumentNullException(ExceptionArgument.task); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to have add ThrowHelper to the CoreFX package instead so that a copy of this method is not stamped into each ValueTask instantiaion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there an issue for that, or anyone working on it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not think so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I'll open an issue. In the meantime I can just use ifdefs if you prefer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not understand why you would not want to just do it as part this set of changes ... it just requires extra change in your CoreFX PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about corert?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move to internal non-generic static class in meantime?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, were you suggesting adding a ThrowHelper to corefx rather than moving coreclr's implementation to shared? I thought you were suggesting moving it to shared. If you're just talking about a simple equivalent in corefx, sure, that's easy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, I am just talking about a simple local equivalent for ValueTuple in corefx. I do not think sharing ThrowHelper.cs makes sense.
@@ -74,7 +74,11 @@ internal ConfiguredValueTaskAwaiter(ValueTask<TResult> value, bool continueOnCap | |||
|
|||
/// <summary>Gets the task underlying the incomplete <see cref="_value"/>.</summary> | |||
/// <remarks>This method is used when awaiting and IsCompleted returned false; thus we expect the value task to be wrapping a non-null task.</remarks> | |||
(Task task, bool continueOnCapturedContext) IConfiguredValueTaskAwaiter.GetTask() => (_value.AsTaskExpectNonNull(), _continueOnCapturedContext); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the change to not use ValueTuple here. It will improve .NET Core as well.
ValueTuples are pretty expensive types with large footprint, unfortunately. Not as bad as Linq, but bad enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes me sad
675a5a1
to
de70b09
Compare
@dotnet-bot test Tizen armel Cross Checked Innerloop Build and Test please |
Several updates to ValueTask Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
Several updates to ValueTask Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
Several updates to ValueTask Signed-off-by: dotnet-bot-corefx-mirror <dotnet-bot@microsoft.com>
Several updates to ValueTask Signed-off-by: dotnet-bot-corefx-mirror <dotnet-bot@microsoft.com>
Make ValueTask code more easily shared with corefx
With those changes, we'll be able to fully share the ValueTask code and associated CompilerServices code, other than the three methods in the .CoreCLR.cs file, and can delete corefx's duplicate implementation.
Make ValueTask awaiters readonly structs
Remove defunct CreateAsyncMethodBuilder method
default
.cc: @jkotas, @benaadams